/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on 06-may-2011, 18:37:36
 */
package GUI;

import i18n.LanguageUtils;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;

import GUI.common.ExceptionI18N;
import GUI.common.MissatgePantalla;
import GUI.common.cmd.ClientCommand;
import GUI.common.cmd.Factory;
import GUI.forms.HomePanel;
import GUI.menu.JMenuAnalyzer;
import GUI.menu.JMenuSettings;

public class GUI extends javax.swing.JFrame implements ActionListener {
	public Dimension dimension;	
	

	
    /** Creates new form MainFrame */
    public GUI() {
    	super();
		this.dimension=	new Dimension(400, 250);

    }
    

    
    public void addMenu() {
    	jMenuBar1.add(new JMenuAnalyzer("Menu.Analyzer", this));
        jMenuBar1.add(new JMenuSettings("Menu.Settings", this));        
    }
    
    public void addCommonMenu() {
   
        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 587, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 316, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    public void initComponents() {
        jMenuBar1 = new javax.swing.JMenuBar();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    }

    
	public void setContentPane(Container contentPanel) {
		super.setContentPane(contentPanel);
		this.pack();
	}

	
	public void actionPerformed(ActionEvent actionEvent) {
		ClientCommand cmd = Factory.getCommand(actionEvent.getActionCommand());
				
		try {

				cmd.execute(this, actionEvent);
		} catch (ExceptionI18N e) {
			if(e.getTipus() == MissatgePantalla.ERROR && e.getTitle() == "SQL.name") {
			}
			MissatgePantalla.avis(e.getTipus(), e.getMessage());
		}
			
	}

    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
    	if (args.length ==0) {
    		LanguageUtils.setDefaultLanguage("i18n/messages");    		
    	}
    	else if (args.length == 1) {
			Locale localLocale = new Locale(args[0]);
			LanguageUtils.setLanguage("i18n/messages", localLocale);
		}

		
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                GUI gui = new GUI();
        		gui.initComponents();
        		gui.addMenu(); 
        		gui.addCommonMenu();
        		
                gui.setContentPane(new HomePanel(gui));
                gui.setVisible(true);
                gui.pack();
                
            }
        });
    }
    
   private javax.swing.JMenuBar jMenuBar1;
    // End of variables declaration//GEN-END:variables

	
	
	public void resetMenu() {
		this.jMenuBar1.removeAll();
	}
	
}
